/**
 * 
 */
package net.ondev.dutils.tostring;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IType;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;

/**
 * @author Liu Jie
 *
 */
public abstract class BaseActionDelegate {
	static Log log = LogFactory.getLog(BaseActionDelegate.class);
	List<IType> targetElements=new ArrayList<IType>();
	
	ToStringCodesGenerator generator=new ToStringCodesGenerator();
	
	public void run(IAction action) {
		log.info("Start to generate the toString() methods");
		for(IType unit: targetElements){
			generator.generateToStringMethod(unit, false);
		}
		log.info("End of generating toString() methods." );
	}



	/**
	 * @param i
	 */
	protected void addTargetElements(ICompilationUnit i) {
		try{
		IType[] types = i.getAllTypes();
		for(IType type: types){
			targetElements.add(type);
		}
		}catch(Exception e){
			log.error(e);
		}
	}
}
